package com.guoxw.headerdemo.view;

import android.annotation.SuppressLint;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;

import com.guoxw.headerdemo.R;
import com.guoxw.headerdemo.adapter.MyAdapter;
import com.guoxw.headerdemo.bean.Music;

import java.util.ArrayList;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link MusicFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class MusicFragment extends Fragment {

    private static final String TAG = MusicFragment.class.getName().toString();

    private RecyclerView rv_music;
    private ArrayList<Music> musicArrayList;
    private LinearLayoutManager linearLayoutManager;

    private MyAdapter myAdapter;

    public MusicFragment() {
        // Required empty public constructor
    }

    public static MusicFragment newInstance() {
        MusicFragment fragment = new MusicFragment();

        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @SuppressLint("MissingInflatedId")
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment

        View inflate = inflater.inflate(R.layout.fragment_music, container, false);
        rv_music = (RecyclerView) inflate.findViewById(R.id.rv_music);
        musicArrayList = new ArrayList<>();

        for (int i = 0; i < 50; i++) {

            Music music = new Music(i + "", "musicName+" + i);
            musicArrayList.add(music);
        }

        linearLayoutManager = new LinearLayoutManager(getContext());
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);

        myAdapter = new MyAdapter(getContext(),musicArrayList);

        rv_music.setLayoutManager(linearLayoutManager);
        rv_music.setAdapter(myAdapter);

        return inflate;
    }

//    @Override
//    public boolean onInterceptTouchEvent(MotionEvent ev) {
//        switch (ev.getAction()) {
//            case MotionEvent.ACTION_DOWN:
//                Log.d(TAG, "onInterceptTouchEvent:   MyFrameLayout   MotionEvent.ACTION_DOWN ");
//                break;
//
//            case MotionEvent.ACTION_MOVE:
//
//                Log.d(TAG, "onInterceptTouchEvent: :   MyFrameLayout MotionEvent.ACTION_MOVE");
//                break;
//
//            case MotionEvent.ACTION_UP:
//
//                Log.d(TAG, "onInterceptTouchEvent: :   MyFrameLayout MotionEvent.ACTION_UP");
//                break;
//
//        }
//        return super.onInterceptTouchEvent(ev);
//    }
//
//    @Override
//    public boolean onTouchEvent(MotionEvent event) {
//        switch (event.getAction()) {
//            case MotionEvent.ACTION_DOWN:
//                Log.d(TAG, "onTouchEvent::   MyFrameLayout MotionEvent.ACTION_DOWN ");
//                break;
//
//            case MotionEvent.ACTION_MOVE:
//
//                Log.d(TAG, "onTouchEvent::   MyFrameLayout  MotionEvent.ACTION_MOVE");
//                break;
//
//            case MotionEvent.ACTION_UP:
//
//                Log.d(TAG, "onTouchEvent::   MyFrameLayout  MotionEvent.ACTION_UP");
//                break;
//
//        }
//        return super.onTouchEvent(event);
//    }


}